package chat.view.menus;


import chat.clients.XmppClient;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;

public class ClientMenuItem extends JMenuItem {
    /**
     *
     */
    private static final long serialVersionUID = 1591931693043215702L;

    public enum Type {
        ALWAYS, ONLINE, OFFLINE
    }

    public ClientMenuItem(XmppClient client, String label, final Type type, ActionListener actionListener) throws HeadlessException {
        super(label);

        setEnabled(type != Type.ONLINE);

        addActionListener(actionListener);

        if (type == Type.ALWAYS)
            return;

        client.on(XmppClient.LOGGED_IN, (o1, arg1) -> setEnabled(type == Type.ONLINE));

        client.on(XmppClient.LOGGED_OUT, (o, arg) -> setEnabled(type == Type.OFFLINE));
    }
}
